package com.itheima.job2;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //1.创建客户端socket对象，并指定服务端程序的主机地址和端口
        Socket client = new Socket("127.0.0.1", 6666);
        //2.socket通道创建字节输出流
        OutputStream os = client.getOutputStream();
        //3.将字节输出流包装成数据输出流
        DataOutputStream dos = new DataOutputStream(os);
        //4.使用数据输出流输出信息
        dos.writeUTF("客户端：我来了，你好");
        //5.当不再发送数据，告诉服务端，发送发送完毕
        client.shutdownOutput();
        //6.获取网络输入流读取服务端发送的数据
        InputStream is = client.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        System.out.println(dis.readUTF());
        //7.释放资源
        client.close();
    }
}
